﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Org.BouncyCastle.Math.EC.ECCurve;

namespace ConfigurationCommon
{
    public static class ConfigurationStaticHelper
    {
        static IConfiguration _configuration;

        public static string _usermysqlConnectionString { get { return _configuration["ConnectionStrings:usermysqlConnectionString"]; } }
        public static string _gpMongodbConnectionString { get { return _configuration["ConnectionStrings:gpMongodbConnectionString"]; } }

        private static void SetConfig()
        {
            var configBuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            _configuration = configBuilder.Build();
            
            ChangeToken.OnChange(()=>_configuration.GetReloadToken(), () => {
            });
        }

        public static string GetConfig(string path) {
            if (_configuration == null)
            {
                SetConfig();
            }

            return _configuration[path];
        }

    }
}
